package com.photo.tagger;



import java.io.IOException;

import android.app.Activity;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.ImageView;

public class TagUI1 extends Activity {
	private Bitmap myBitmap;
	public Uri imageUri;
	public String imagePath;
	ExifInterface exif;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
    	Log.i("tag", "vachindirooooooooooooooooooooooooooooooooooooo");
        super.onCreate(savedInstanceState);
        Log.i("tag", "vachindirooooooooooooooooooooooooooooooooooooo");
        setContentView(R.layout.exif_test);
        Log.i("tag", "vachindirooooooooooooooooooooooooooooooooooooo");
        imageUri = Uri.parse(getIntent().getExtras().getString("imageUri"));
        Log.i("tag", "gunjukundi");
        imagePath=this.getRealPathFromURI(imageUri);
        Log.i("tag", "path is"+ imagePath);
        myBitmap = BitmapFactory.decodeFile(imagePath);
        setContentView(R.layout.exif_test);
		ImageView preview= (ImageView) findViewById(R.id.rimage);
		preview.setImageBitmap(myBitmap);
		exifTest();
		//Bitmap c=myBitmap.createScaledBitmap(myBitmap, 200, 200, true);
        //setContentView(new MyView(this));
    }

    public String getRealPathFromURI(Uri contentUri)
	{
		// can post image
		String[] proj = { MediaStore.Images.Media.DATA };
		Cursor cursor = managedQuery(contentUri, proj, // Which columns to
				// return
				null, // WHERE clause; which rows to return (all rows)
				null, // WHERE clause selection arguments (none)
				null); // Order-by clause (ascending by name)
		int column_index = cursor
				.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
		cursor.moveToFirst();
		return cursor.getString(column_index);
	}
    public void exifTest()
    {
    	try {
			exif= new ExifInterface(imagePath);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	//exif.setAttribute(ExifInterface.TAG_GPS_TIMESTAMP, "dasfhsdjkfd");
    	//exif.setAttribute("Test", "Tested");
    	try {
			exif.saveAttributes();
			
			
			Log.i("tag","dheenamma save aindhi");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//exif.setAttribute(tag, value)
    	//String dat1 = exif.getAttribute(ExifInterface.);
    	String dat = exif.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP);
    	int i;
    	Log.i("tag", dat + "   adi sangati");
    }
}
